/**
 * @author Alexander Sutherland (tfy11asd)
 * @date 30/05/2012
 * 
 * Position is a class primarily in charge of navigating the maze
 * by fetching surrounding positions. Position is also in charge
 * of making sure that if a position is generated that is out of 
 * bounds then both its X and Y value will be set to -1 so
 * that other classes will be aware of invalid positions.
 * * 
 */
public class Position {
	
	private int x;
	private int y;
   
   /**
   * Position recives two Integers that represent the positions
   * X and Y values in a grid.
   */
	
	public Position(int x,int y)
	{
			if(x >= 0 && y >=0 && x<50 && y<50)
			{
				this.x = x;
				this.y = y;
			}
			else
			{
				this.x = -1;
				this.y = -1; 
			}
	}
	
	
	public int getX()
	{
		return x;
	}
	
	public int getY()
	{
		return y;
	}
	
	
	public Position getPosToSouth()
	{
		Position south = new Position(x,y+1);
		return south;
	}
	
	public Position getPosToNorth()
	{
		Position north = new Position(x,y-1);
		return north;
	}
	
	public Position getPosToWest()
	{
		Position west = new Position(x-1,y);
		return west;
	}
	
	public Position getPosToEast()
	{
		Position east = new Position(x+1,y);
		return east;
	}
	public Position getPosToSouthEast()
	{
		Position south = new Position(x+1,y+1);
		return south;
	}
	
	public Position getPosToNorthWest()
	{
		Position north = new Position(x-1,y-1);
		return north;
	}
	
	public Position getPosToSouthWest()
	{
		Position west = new Position(x-1,y+1);
		return west;
	}
	
	public Position getPosToNorthEast()
	{
		Position east = new Position(x+1,y-1);
		return east;
	}
	/**
	 * equals is a way of comparing two positions by looking at their X and Y variables.
	 * @param Object o
	 */
	
	public boolean equals(Object o)
	{
		if(o == null)
		{
			return false;
		}
		if(getClass() != o.getClass())
		{
			return false;
		}
		
		Position other = (Position) o;
		
		if(getX() == other.getX() && getY() == other.getY())
		{
			return true;
		}
		else
		{
			return false;
		}
		
	}
	/**
	 * hahsCode hashes a unique integer for every position the maze.
	 */
	
	public int hashCode()
	{
		return ((x+1)*33)^(y+1);
	}

}
